package com.yty.system.oauth.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yty.system.oauth.config.UserDetailService;
import com.yty.system.oauth.entity.ProjectInfo;
import com.yty.system.oauth.entity.SysUser;
import com.yty.system.oauth.mapper.ProjectInfoMapper;
import com.yty.system.oauth.service.IProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yegang
 * @since 2023-03-24
 */
@Service
public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, ProjectInfo> implements IProjectInfoService {

    @Autowired
    private ProjectInfoMapper projectInfoMapper;

    @Autowired
    @Qualifier("taskExecutor1")
    private TaskExecutor taskExecutor;

    @Override
    public void insert() throws Exception {
        SysUser currentUser = UserDetailService.getCurrentUser();
        long s2 = System.currentTimeMillis();
        List<List<ProjectInfo>> lists = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            lists.add(getProjectList(currentUser.getId()));
        }
        for (List<ProjectInfo> list : lists) {
            saveBatch(list);
        }
    }

    private List<ProjectInfo> getProjectList(String id) {
        List<ProjectInfo> list = new ArrayList<>();
        String[] projectNames = {"恒居地产","金丰物业管理有限公司","环球物业管理有限公司","青澳湾房地产公司","浙江义乌坐标房地产营销策划有限公司","云凯房地产开发公司",
                "冠顶房产公司","大龙地产","金宏地产公司","伟博房地产公司","昱龙房地产开发公司","傲宇房产置业公司","深盛佳物业管理有限公司","舒豪房地产公司",
                "德瑞房地产开发有限公司","皖美房地产公司","东山之家","深源房地产公司",
                "皖美房地公司","郡威房产公司","顺成地产公司","武汉汉商人信置业有限公司","中鸿房地产公司",
                "洪阳房地产开发公司","舒阁房地产公司","长汇房地产开发有限公司","西海房地产公司","大诚房产有限公司","澄海岭亭房地产公司","鸿中房地产公司",
                "华能房地产开发公司","宇虹房地产开发公司","伟博房地产公司","逸景房地产公司","世茂房地产开发公司","舒阁房地产公司","冠顶房产公司",
                "万邦房地产公司","弘泰地产公司","三河市雷捷房地产开发有限公司","鸿泰房产公司","龙德房地产公司",
                "恒达地产器公司","宏发房地产公司","博基房地产公司","深源房地产公司","宏远地产器公司","鸿基房地产公司","瑞福房地产开发公司","弘润房地产开发公司"};


        String[] Surname= {"公孙","仲孙","令狐","钟离","宇文","长孙","慕容","鲜于","闾丘","司徒","司空","兀官","司寇",
                "南门","呼延","子车","端木","公西","车正","公良","拓跋","夹谷","宰父","谷梁","段干","百里","东郭",
                "梁丘","左丘","东门","西门","南宫","第五","公仪","公乘","太史","仲长","叔孙","尔朱","东乡","相里","胡母","司城","张廖",
                "毋丘","贺兰","綦毋","屋庐","北宫","王孙"};

        String[] banks = {"中国工商银行","招商银行","中国农业银行","中国建设银行","中国银行",
                "中国民生银行","中国光大银行","中信银行","交通银行","兴业银行","中国人民银行","华夏银行",
                "深圳发展银行","广东发展银行"};
        int index = 0;
        for (int i = 0; i < projectNames.length; i++) {
            String bankName = banks[index];
            if (index < 13) {
                index ++;
            }else {
                index = 0;
            }
            ProjectInfo projectInfo = new ProjectInfo();
            projectInfo.setProjectName(projectNames[i])
                    .setLedgerName(Surname[i])
                    .setBankName(bankName)
                    .setUserId(id)
                    .setBankNo("622848"+IdWorker.getId());
            list.add(projectInfo);
        }
        return list;
    }
}
